package com.sita.linboard.person;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sita.linboard.DriverVehicle.DriverUnBindVehicleActivity;
import com.sita.linboard.MainMessage.DriverDayMsgRequest;
import com.sita.linboard.R;
import com.sita.linboard.base.ActivityCollector;
import com.sita.linboard.base.BaseActivity;
import com.sita.linboard.base.BaseApplication;
import com.sita.linboard.driverInfo.DriverSetInfoActivity;
import com.sita.linboard.driverInfo.MsgCenterActivity;
import com.sita.linboard.http.RestClient;
import com.sita.linboard.utils.SpUtils;
import com.sita.linboard.utils.ToastUtils;
import com.sita.linboard.wallet.MyWalletActivity;
import com.squareup.picasso.Picasso;

import retrofit.Callback;
import retrofit.RetrofitError;
import retrofit.client.Response;

/**
 * Created by Jason on 2016/8/26.
 */
public class DriverInfoActivity extends BaseActivity implements View.OnClickListener{
    private LinearLayout img_back,myTrip;
    private TextView headTitle,trip_count,sore;
    private RelativeLayout walletBt,person_info,msg_center,recommend,my_set,myVehicle;
    private SettingBackBean backBean;
    private ImageView head_img;
    private TextView nickNameTx;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }
     private void getAllDatafromSer(){

         DriverDayMsgRequest request = new DriverDayMsgRequest();
         request.user_id = SpUtils.getString("AccoundID",null, BaseApplication.getContext());
         RestClient.getRestService().MySetting(request, new Callback<SettingBackBean>() {
        @Override
        public void success(SettingBackBean settingBackBean, Response response) {
            backBean = new SettingBackBean();
            backBean = settingBackBean;
            if (settingBackBean.getErrorCode().equals("0")&&settingBackBean.getData()!=null){
                trip_count.setText(String.valueOf(settingBackBean.getData().getMyTripsCount()));
                sore.setText(String.valueOf(settingBackBean.getData().getScore()));
                try {
                    Picasso.with(BaseApplication.getContext()).load(settingBackBean.getData().getAccount().getAvatar()).into(head_img);
                }catch (IllegalArgumentException exception) {

                }
                nickNameTx.setText(settingBackBean.getData().getAccount().getNickName());
            }
        }

        @Override
        public void failure(RetrofitError error) {

        }
    });
}
    @Override
    protected void initData() {
         headTitle.setText("个人设置");
    }

    @Override
    protected void onStart() {
        super.onStart();
        getAllDatafromSer();
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        ActivityCollector.addActivity(this);
        img_back = bindView(R.id.img_back);
        img_back.setVisibility(View.VISIBLE);
        img_back.setOnClickListener(this);
        headTitle = bindView(R.id.head_title);
        headTitle.setVisibility(View.VISIBLE);
        walletBt = bindView(R.id.my_wallet);
        walletBt.setOnClickListener(this);
        person_info = bindView(R.id.jump_to_info);
        person_info.setOnClickListener(this);
        msg_center =  bindView(R.id.my_messagecenter);
        msg_center.setOnClickListener(this);
        recommend =  bindView(R.id.my_recommended);
        recommend.setOnClickListener(this);
        my_set = bindView(R.id.my_setting);
        my_set.setOnClickListener(this);
        trip_count = bindView(R.id.tripcount);
        sore =bindView(R.id.score);
        head_img = bindView(R.id.user_headimg);
        myTrip = bindView(R.id.my_trip);
        myTrip.setOnClickListener(this);
        myVehicle = bindView(R.id.my_vehicle);
        myVehicle.setOnClickListener(this);
        nickNameTx = bindView(R.id.nickName);
    }

    @Override
    protected int getId() {
        return R.layout.activity_driverinfo;
    }
    public static void DriverinfoIntent(Context context){
        Intent intent = new Intent(context,DriverInfoActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ActivityCollector.removeActivity(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.my_wallet:
                MyWalletActivity.WalletIntent(this);
                break;
            case R.id.img_back:
                finish();
                break;
            case R.id.jump_to_info:
                if (backBean!=null){
                    DriverSetInfoActivity.DriverIntent(this,backBean);
                }else {
                    ToastUtils.show("服务器异常",3);
                }
                break;
            case R.id.my_messagecenter:
                MsgCenterActivity.MsgCenterIntent(this);
                break;
            case R.id.my_recommended:
                RecommendActivity.RecommendIntent(this);
                break;
            case R.id.my_setting:
                SettingActivity.SettingIntent(this);
                break;
            case R.id.my_trip:
                DriverTripActivity.DriverTripIntent(this);
                break;
            case R.id.my_vehicle:
                DriverUnBindVehicleActivity.DriverIntent(this);
                break;
        }
    }
}
